/**
 * Created by TypeSDK 2016/10/10.
 */

var log4js = require('log4js');
log4js.configure({

  appenders: {
    console: {type: 'console'},
    file: {
      type: 'file',
      absolute: true,
      filename: 'logs/console.log',
      maxLogSize: 1024 * 1024 * 200,
      backups: 5,
      category: 'console',
      layout: {
        type: 'pattern',
        pattern: "[%d][%p][%h][%z]- %x{lurl} %n %m",
        tokens: {
          lurl: function () {
            var logger = log4js.getLogger('console');
            return logger.requrl ? logger.requrl : 'NOURL';
          },
          ls: function () {
            var logger = log4js.getLogger('console');
            return logger.reqparam ? JSON.stringify(logger.reqparam) : '{}';
          }
        }
      }
    },
    dateFile: {
      compress: true,
      type: 'dateFile',
      absolute: true,
      filename: 'logs/CDZS',
      backups: 3,
      pattern: "_yyyy-MM-dd.log",
      alwaysIncludePattern: true,
      category: 'CDZS'
    }

  },
  categories: {
    default: { appenders: ['console'], level: 'trace' },
    CDZS: { appenders: ['file',"dateFile"], level: 'trace' },
  }
});
//var logger = log4js.getLogger(name);
//logger.setLevel('INFO');

var loggerf = function (name) {
  var logger = log4js.getLogger(name);
  logger.level = 'all';
  // logger.debug('debug');
  // logger.info('info');
  // logger.error('error');
  // logger.fatal('Tfatal');
  // logger.trace('trace');
  // logger.warn('warn');

  return logger;
};
exports.loggerf = loggerf;
exports.logger = function (name) {
  return log4js.connectLogger(loggerf(name), {level: 'auto'})
};

